package cuishifeng.blog.learn.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author cuishifeng <cuishifeng0207@163.com>
 * Created on 2021-04-25
 */
//@Component
public class SpringBeanLiveDemo
        implements FactoryBean<SpringBeanLiveDemo>, InitializingBean, BeanPostProcessor, BeanNameAware,
        BeanFactoryAware, BeanClassLoaderAware, DisposableBean {


    public void selfMethod() {
        System.out.println("hello==============");
    }

    public SpringBeanLiveDemo() {
        System.out.println("SpringBeanLiveDemo init");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean afterPropertiesSet");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("BeanNameAware setBeanName s:" + s);
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("BeanClassLoaderAware setBeanClassLoader");
    }


    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("BeanFactoryAware setBeanFactory");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean destroy");
    }


    @Override
    public SpringBeanLiveDemo getObject() throws Exception {
        System.out.println("FactoryBean getObject");
        return new SpringBeanLiveDemo();
    }

    @Override
    public Class<?> getObjectType() {
        System.out.println("FactoryBean getObjectType");
        return SpringBeanLiveDemo.class;
    }

    @Override
    public boolean isSingleton() {
        System.out.println("FactoryBean isSingleton");
        return true;
    }
}
